using System;
using System.Data;
using System.Xml;
using System.IO;



namespace OR.Lazarus.Business.Entities.Config
{
	public enum TemplateTypes { Source, Compiled, Validator, Compiler, Generator };

   public class ConfigDetail : OR.Lazarus.Business.Entities.Config.Lazarus.ConfigDetail
   {
		public const string	OVERWRITE_ALWAYS	= "Always";
		public const string	OVERWRITE_REGIONS	= "Regions";
		public const string	OVERWRITE_NEVER	= "Never";

		public void LoadXmlFile( string pFilename )
		{
			XmlDocument vDocument = new XmlDocument();

			if ( String.IsNullOrEmpty( pFilename ) )
			{
				throw new ApplicationException( "ConfigDetail.LoadXmlFile failed:  The Filename was not specified." );
			}
			else if ( !File.Exists( pFilename ) )
			{
				throw new ApplicationException( "ConfigDetail.LoadXmlFile failed: The Filename [" + pFilename + "] was not found." );
			}
			else
			{
				vDocument.Load( pFilename );

				this.LoadXml( vDocument.DocumentElement );
			}
		}

		protected virtual ClassReferenceDetail GetAndValidateTemplate( TemplateTypes pType )
		{
			ClassReferenceDetail vReturn = null;

			vReturn = mEngineTemplates[ pType ];

			if ( vReturn == null )
			{
				throw new ApplicationException( "ConfigDetail.Validate() failed: you must supply Assembly and Class information for the " + pType.ToString() + " template." );
			}

			return ( vReturn );
		}

		public void Validate()
		{
			// Make sure all Template Types are specified.
			ClassReferenceDetail vSource = GetAndValidateTemplate( TemplateTypes.Source );
			ClassReferenceDetail vCompiled = GetAndValidateTemplate( TemplateTypes.Compiled );
			ClassReferenceDetail vValidator = GetAndValidateTemplate( TemplateTypes.Validator );
			ClassReferenceDetail vCompiler = GetAndValidateTemplate( TemplateTypes.Compiler );
			ClassReferenceDetail vGenerator = GetAndValidateTemplate( TemplateTypes.Generator );
		}
   }
}
   